package com.androidbook.bro;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.io.Serializable;

public class Wheel_Joy implements Serializable {

	private static final long serialVersionUID = 4716040394664401641L;
	private double key_acs;
	private int key_up;
	private int key_down;
	private int key_A;
	private int key_B;
	private int key_C;
	private int key_D;

	public Wheel_Joy() {

	}

	public void keyFilling() {
		key_up = 0;
		key_down = 0;
		key_acs = 0;
		key_A = 0;
		key_B = 0;
		key_C = 0;
		key_D = 0;
	}

	public void keyFilling(double aKey_Acs, int aKey_Up, int aKey_Down,
			int aKey_Left, int aKey_Right, int aKey_A, int aKey_B, int aKey_C,
			int aKey_D) {
		key_up = aKey_Up;
		key_down = aKey_Down;
		key_acs = aKey_Acs;
		key_A = aKey_A;
		key_B = aKey_B;
		key_C = aKey_C;
		key_D = aKey_D;

	}

	public void keyFilling(String aKey_Name, int aValue) {
		if (aKey_Name == "UP") {
			key_up = aValue;
		}
		if (aKey_Name == "DOWN") {
			key_down = aValue;
		}
		if (aKey_Name == "A") {
			key_A = aValue;
		}
		if (aKey_Name == "B") {
			key_B = aValue;
		}
		if (aKey_Name == "C") {
			key_C = aValue;
		}
		if (aKey_Name == "D") {
			key_D = aValue;
		}
	}

	public void keyFilling(String aKey_Name, double aValue) {
		if (aKey_Name == "ACS") {
			key_acs = aValue;
		}
	}

	public int keySee(String aKey_Name) {
		if (aKey_Name == "UP") {
			return key_up;
		}
		if (aKey_Name == "DOWN") {
			return key_down;
		}
		if (aKey_Name == "A") {
			return key_A;
		}
		if (aKey_Name == "B") {
			return key_B;
		}
		if (aKey_Name == "C") {
			return key_C;
		}
		if (aKey_Name == "D") {
			return key_D;
		}
		return -1;

	}

	public double acsSee() {
		return key_acs;
	}

	public void keyShow() {
		System.out.print(key_up);
		System.out.print(" ");
		System.out.print(key_down);
		System.out.print(" ");
		System.out.print(key_acs);
		System.out.print(" ");
		System.out.print(key_A);
		System.out.print(" ");
		System.out.print(key_B);
		System.out.print(" ");
		System.out.print(key_C);
		System.out.print(" ");
		System.out.print(key_D);
		System.out.println();
	}

	public void keyHandler() {
		try {
			Robot robot0 = new Robot();
			if (key_up == 1) {
				robot0.keyPress(KeyEvent.VK_UP);
			} else {
				robot0.keyRelease(KeyEvent.VK_UP);
			}
			if (key_down == 1) {
				robot0.keyPress(KeyEvent.VK_DOWN);
			} else {
				robot0.keyRelease(KeyEvent.VK_DOWN);
			}
			if (key_acs <= -3) {
				robot0.keyRelease(KeyEvent.VK_RIGHT);
				robot0.keyPress(KeyEvent.VK_LEFT);
			}
			if (key_acs >= 3) {
				robot0.keyRelease(KeyEvent.VK_LEFT);
				robot0.keyPress(KeyEvent.VK_RIGHT);
			}
			if ((key_acs <= 3) && (key_acs >= -3)) {
				robot0.keyRelease(KeyEvent.VK_LEFT);
				robot0.keyRelease(KeyEvent.VK_RIGHT);
			}
			if (key_A == 1) {
				robot0.keyPress(KeyEvent.VK_SPACE);
			} else {
				robot0.keyRelease(KeyEvent.VK_SPACE);
			}
			if (key_B == 1) {
				robot0.keyPress(KeyEvent.VK_CONTROL);
			} else {
				robot0.keyRelease(KeyEvent.VK_CONTROL);
			}
			if (key_C == 1) {
				robot0.keyPress(KeyEvent.VK_ENTER);
			} else {
				robot0.keyRelease(KeyEvent.VK_ENTER);
			}
			if (key_D == 1) {
				robot0.keyPress(KeyEvent.VK_ESCAPE);
			} else {
				robot0.keyRelease(KeyEvent.VK_ESCAPE);
			}

		} catch (AWTException e) {

			e.printStackTrace();

		}
	}

}
